<%@ page pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<form:form commandName="model" cssClass="validate"
	action="bpm/nodeUser/save">
	<form:hidden path="id" />
	<form:hidden path="bpmNodeSettingId" />
	<table class=" form-table">
		<tbody>
			<tr>
				<td class="td1">处理人类型：</td>
				<td class="td2"><form:select path="assignType"
						data-width="340px">
						<form:option value="0">提交人</form:option>
						<form:option value="10">上一步提交人</form:option>
						<form:option value="1">特定角色</form:option>
						<form:option value="11">项目中的特定角色</form:option>
						<form:option value="2">特定成员</form:option>
						<form:option value="3">表单内成员帐号</form:option>
						<form:option value="31">表单内成员id</form:option>
						<form:option value="4">特定部门下所有成员</form:option>
						<form:option value="6">特定已处理步骤下的处理人</form:option>
						

						<c:if test="${not empty all }">
							<form:option value="5">任务处理人</form:option>
						</c:if>
 
					</form:select></td>
			</tr>
			<tr id="trCmpIds">
				<td class="td1"><label id="lbCpmIds">提交人</label>：</td>
				<td class="td2"><form:hidden path="cmpIds" />
					<div style="display:none" id="divRoleSelect">
						<form:select path="" items="${roles}" itemLabel="name"
							itemValue="id" id="roleSelect" onchange="selectOnchange(this)" />
					</div>
					
					<div style="display:none" id="divNodeStepSelect">
						<form:select path="" items="${nodeList}" itemLabel="name"
							itemValue="id" id="stepsSelect" onchange="selectOnchange(this)" />
					</div>
					
					<div style="display:none" id="divPreUser">
						<form:select path="" id="dbEntityFieldSelect"
							onchange="selectOnchange(this)">
							<form:options items="${fields}" itemLabel="name"
								itemValue="columnName" />
						</form:select>
					</div>


					<div style="display:none" id="divDbEntityFieldSelect">
						<form:select path="" id="dbEntityFieldSelect"
							onchange="selectOnchange(this)">
							<form:options items="${fields}" itemLabel="name"
								itemValue="columnName" />
						</form:select>
					</div>
					<div style="display:none" id="divUserSelect">
						<isperp:departmentUser displayValue="${cmpNames }" id="userSelect"   valueControlId="cmpIds"
							afterSelected="$('#cmpNames').val(row[0]+'('+row[1]+')');"
							idFieldName="name">
						</isperp:departmentUser>
					</div>
					<div style="display:none" id="divDepartmentSelect">

						<isperp:treeSelector id="selectParentDepartment"
							url="app/department/getTree" valueControlId="cmpIds"
							displayValue="${model.cmpNames}"
							afterSelected="$('#cmpNames').val(treeNode.treenodeNamePath);"></isperp:treeSelector>
					</div>


					 
			</tr>
			<tr>
				<td class="td1">显示名称：</td>
				<td class="td2"><form:input path="cmpNames"
						cssStyle="width:85%" /></td>
			</tr>


			<!-- 
			<tr>
				<td class="td1">代码：</td>
				<td class="td2"><textarea rows="10" cols=""></textarea>
				</td>
			</tr>
 -->
		</tbody>
	</table>

</form:form>
<isperp:buttonList>
	<button class="submit" onclick="saveUserNode();return false;">
		<span class="icon icon-save"></span>保存
	</button>
</isperp:buttonList>


<script type="text/javascript">
	function saveUserNode() {

		var $el = $("#assignType");
		var v = $el.val();

		if (v == "22" || v === "23") {
			$("#cmpIds").val($("#dbEntityFieldSelectForCustomer").val() + "|" + $("#txtCustomer").val());
		} else if (v == "24") {
			$("#cmpIds").val($("#dbEntityFieldSelectForCustomer").val() + "|" + $("#cmpIds").val());

		}

		isperp.submitForm({
			success : function() {
				isperp.reloadParentControl();
				isperp.closeDialog();
			}
		});
	}

	function selectOnchange(obj) {
		$("#cmpIds").val($(obj).val());
		$("#cmpNames").val($(obj).find("option:selected").text());
	}

	$("#assignType").change(function() {
		$("#cmpIds,#cmpNames").val("");

		$("#userSelect,#selectParentDepartment").val("");

		assignTypeOnchange();

	});

	function assignTypeOnchange() {
		var $cmpIds = $("#cmpIds");
		var cmpIdsVal = $cmpIds.val();

		var $el = $("#assignType");
		var v = $el.val();
		var $trCmpIds = $("#trCmpIds");
		$trCmpIds.show();
		$("#divDepartmentSelect,#divRoleSelect,#divUserSelect,#divDbEntityFieldSelect,#divNodeStepSelect").hide();
		$("#forCustomer,#divDbEntityFieldSelectForCustomer").hide();
		switch (v) {
		case "0":
			$trCmpIds.hide();
			$cmpIds.val("bpmProcessCreator");
			$("#cmpNames").val("流程发起人");
			break;
		case "10":
			$trCmpIds.hide();
			$cmpIds.val("bpmCurrentUser");
			$("#cmpNames").val("上一步提交人");

			break;
		case "1":
		case "11":
			var url = "";
			$("#divRoleSelect").show();
			$("#lbCpmIds").html("角色名称");
			$cmpIds.val($("#roleSelect").val());
			$("#cmpNames").val($("#roleSelect").find("option:selected").text());
			break;
		case "111":
			$trCmpIds.hide();
			$cmpIds.val("projectMembers");
			$("#cmpNames").val("项目中的所有成员");
            break;
		case "2":
			$("#lbCpmIds").html("成员帐号");
			$("#divUserSelect").show();
			break;
		case "3":
		case "31":
			$("#divDbEntityFieldSelect").show();
			$("#lbCpmIds").html("表单中帐号");
			$("#dbEntityFieldSelect").val(cmpIdsVal);
			$("#cmpNames").val($("#dbEntityFieldSelect").find("option:selected").text());
			break;

		case "4":
			$("#divDepartmentSelect").show();
			$("#lbCpmIds").html("部门名称");
			break;

		case "5":
			$trCmpIds.hide();
			$cmpIds.val("bpmProcesser");
			$("#cmpNames").val("任务处理人");
			break;
		case "6":
			var url = "";
			$("#divNodeStepSelect").show();
			$("#lbCpmIds").html("节点名称");
			$cmpIds.val($("#stepsSelect").val());
			$("#cmpNames").val($("#stepsSelect").find("option:selected").text());
			break;

	 
		}

	}

	assignTypeOnchange();
</script>